<template>
	<view class="container">
		<form @submit="formSubmit">
			<view class="line border-b"><view class="title">昵称<text class="red">*</text></view><view class="value"><input name="NickName" type="text" placeholder="请输入昵称" :value="User.NickName"/></view></view>
			<view class="line border-b"><view class="title">手机号</view><view class="value"><input name="Mobile" type="text" placeholder="请输入手机号" :value="User.Mobile"/></view></view>
			<button class="save" form-type="submit">
				保存
			</button>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Upload:false,
				User:{}
			};
		},
		onLoad() {
			this.Find_MyData();
		},
		methods:{
			DelImg(){
				this.Util.Confirm("您确定要删除吗？",()=>{
					this.User.SkEwm="";
				});
			},
			ChooseImg(){
				uni.chooseImage({
				    count: 1, //默认9
				    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				    sourceType: ['camera','album'], //从相册选择
				    success: res=> {
						this.Upload=true;
				        this.User.SkEwm=res.tempFilePaths[0];
				    }
				});
			},
			Find_MyData(){
				var data = {};
				data.Act="Find_MyData";
				this.Util.Loading("请稍候...");
				this.Util.Post(data, json=>{
					uni.stopPullDownRefresh();
					this.Util.HideLoading();
					this.User = json.Data.User;
				});
			},
			formSubmit(e){
				var data=e.detail.value;
				data.Act="Save_User";
				if(data.NickName.trim()==""){
					this.Util.Toast("请输入昵称");
					return false;
				}
				this.Util.Loading("请稍候...");
				this.Save(data);
			},
			Save(data){
				this.Util.Post(data, json=>{
					this.Util.HideLoading();
					if(json.State){
						this.Util.Toast(json.Msg, function(){
							uni.$emit("SaveUser");
							uni.navigateBack({
								delta:1
							});
						});
					}else{
						this.Util.Alert(json.Msg);
					}
				});
			},
			PrevImg(urls,index){
				uni.previewImage({
					current:index,
					urls: urls,
					longPressActions: {
						itemList: ['保存图片'],
						success: data=> {
							uni.saveImageToPhotosAlbum({
								filePath: urls[data.index],
								success: d=> {
									this.Util.Toast("已保存至系统相册");
								}
							});
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.container{width:100%; padding-top:20rpx; padding-bottom:120rpx;
		.line{width:100%; min-height: 100rpx; height:auto; padding-left:20rpx; padding-right: 20rpx; position: relative; z-index:1; background-color: #ffffff; display:flex; flex-direction: row; font-size:36rpx; 
			.title{width:170rpx; min-height:100rpx; display:flex; align-items: center;}
			.tip{width:auto; line-height: 160rpx; color:#999999; font-size:32rpx;}
			.value{flex:1; min-height:100rpx; line-height: 100rpx; color:#999999; text-align: right; overflow: hidden;
				input{width:100%; min-height:100rpx; text-align: right; color:#000000;}
				.right{width:100%; float:right; width:auto; overflow: hidden; .image{width:60rpx; height:60rpx; float:left; margin-left:10rpx; margin-top:20rpx;}}
				.txt{float:right; width:50rpx; text-align: center;}
				image{width:140rpx; height:140rpx; position: relative;}
				.img{width:140rpx; height:140rpx; position: relative; float:right; margin-right:20rpx;
					.skewm{width:140rpx; height:140rpx; position: relative; z-index:1;}
					.error{width:40rpx; height: 40rpx; position: absolute; top:-15rpx; right:-15rpx; z-index:99;}
				}
			}
			textarea{min-height:600rpx; color:#999999;}
			.img{ image{width:120rpx; height:120rpx; margin-top:16rpx; margin-bottom: 10rpx;}}
			.arrow{width:30rpx; height:30rpx; margin-left:10rpx; margin-top:35rpx;}
			.position{width:50rpx; height:50rpx; margin-left:10rpx;  margin-top:28rpx;}
		}
		.save{width:690rpx; height:88rpx; line-height: 88rpx; margin-top:80rpx; margin-left:30rpx; border-radius:44rpx; font-size:34rpx; text-align:center; color:#ffffff; background:linear-gradient(to right,#00bdfd,#03aee8);}
	}
</style>
